package mars.game.util;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import mars.game.core.MarsRuntime;

import android.graphics.Rect;

public class Tools
{
	
	public static String STAGE = "stage";
	
	public static Properties pro = new Properties();
	
	public static final boolean pointInRect(int x, int y, Rect rect)
	{

		// System.out.println("rect.left:" + rect.left);
		// System.out.println("rect.right:" + rect.right);
		// System.out.println("rect.top:" + rect.top);
		// System.out.println("rect.bottom:" + rect.bottom);
		
		if (x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom)
		{
			return true;
		}
		else
		{
			return false;
		}
		
	}
	
	static public Boolean save(String... objs)
	{

		for (String value : objs)
		{
			pro.put(STAGE, value);
		}
		
		FileOutputStream fos = MarsRuntime.getRuntime().openOutFile();
		if (fos == null)
		{
			// 给用户提示错误
			return false;
		}
		try
		{
			pro.store(fos, "");
			return true;
		}
		catch (IOException e)
		{
			// 给用户提示错误
			return false;
		}
	}
	
	static public boolean load()
	{

		Properties pro = new Properties();
		try
		{
			
			FileInputStream fis = MarsRuntime.getRuntime().openInputFile();
			pro.load(fis);
			pro.get(STAGE);
			return true;
		}
		catch (Exception e)
		{
			return false;
		}
		
	}
	
	static public boolean rectJudge(Rect rect1, Rect rect2)
	{
	return 	Rect.intersects(rect1, rect2);
	}
}
